<template>
	<v-forms ref="formRef" :label-width="120"> </v-forms>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted, reactive, toRefs, computed } from 'vue';
import VForms from '/@/components/forms/v-forms.vue';
import { validateNumber } from '/@/utils/validators';
import { ElMessage, ElMessageBox } from 'element-plus';
import request from '/@/api/develop/dic';
export default defineComponent({
	components: {
		VForms,
	},
	setup() {
		const formRef = ref();

		const state = reactive({});

		const addNew = async (data: any = {}) => {
			let formList: any[] = [
				{
					type: 'select',
					label: '从枚举生成',
					key: 'enumType',
					value: '',
					show: data.id?false: true,
					watch: true,
					options: [],
					placeHolder: '请选择枚举',
					selectOption: {
						type: 'remote',
						loading: false,
						requestMethod: request.getEnumTypeList,
						searchKey: 'enumName',
						value: 'code',
						label: 'name',
                        showMore: [{
                            label: '',
                            key: 'code'
                        }],
						fill: {
							'name': 'name',
							'code': 'code'
						}
					},
					rules: [
						{ required: false, message: '枚举不能为空', trigger: ['blur'] },
					],
				},
				{
					type: 'input',
					key: 'name',
					label: '类型名称',
					value: data.name || '',
					placeHolder: '请输入类型名称',
					rules: [{ required: true, message: '类型名称不能为空', trigger: ['blur', 'change'] }],
				},
				{
					type: 'input',
					key: 'code',
					label: '唯一编码',
					placeHolder: '请输入唯一编码',
					value: data.code || '',
					rules: [{ required: true, message: '唯一编码不能为空', trigger: ['blur', 'change'] }],
				},{
					type: 'input',
					key: 'sort',
					label: '排序',
					placeHolder: '请输入排序',
					value: data.sort || '',
					rules: [{ required: false, message: '排序不能为空', trigger: ['blur', 'change'] }],
				},
				{
					type: 'textarea',
					key: 'remark',
					label: '备注',
					placeHolder: '请输入备注',
					value: data.remark || '',
					rules: [{ required: false, message: '备注不能为空', trigger: ['blur', 'change'] }],
				},
			];

			if (data.id) {
				formList.push({
					type: 'input',
					label: 'id',
					key: 'id',
					show: false,
					value: data.id,
					rules: [{ required: false, message: `id不能为空`, trigger: 'change' }],
				});
			}

			let title = data.id ? '字典类型编辑' : '新增字典类型';

			formRef.value.openDialog(formList, title);
		};
		return {
			formRef,
			addNew,
			...toRefs(state),
		};
	},
});
</script>

<style lang="scss" scoped>
.select-list {
	:deep(.el-form-item) {
		margin: 15px 0;
	}
}
</style>
